package com.atguigu.study.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @auther zzyy
 * @create 2025-03-20 13:59
 */

@Aspect
@Component
@Slf4j
public class RequestLogAspect {
    /* 第一种写法：  where的问题，往哪里下刀cut
    @Pointcut("execution(public * com.atguigu.study.controller.HelloAopController.helloAop(..))")
    public void webLog() {}

    @Before("webLog()")
    public void doBefore(JoinPoint joinPoint) throws Throwable
    {
        System.out.println("---------前置通知:RequestLogAspect");
    }*/

    /**
     * 1   通知      @Before @AfterReturning
     * 2   切面类     xxxAspect
     * 3   连接点     JoinPoint
     * 4   切入点     PointCut
     * 5   织入       weave
     */

    //这是第二种excution
    @Before("execution(public * com.atguigu.study.controller.HelloAopController.hello*(..))")
    public void doBefore(JoinPoint joinPoint) throws Throwable {
        System.out.println("---------前置通知222:RequestLogAspect----> " + joinPoint.getTarget().getClass().getName());
    }

    @AfterReturning("execution(public * com.atguigu.study.controller.HelloAopController.hello*(..))")
    public void doAfterReturning() throws Throwable {
        System.out.println("---------后置通知:doAfterReturning");
    }
}

